<?php
session_start();

$RandomStr = md5(microtime());// md5 to generate the random string

$ResultStr = strtoupper(substr($RandomStr,0,3));//trim digit 

$NewImage =imagecreatefromjpeg("./img/captcha.jpg");//image create by existing image and as back ground 

$LineColor = imagecolorallocate($NewImage,255,55,55);//line color 
$LineColor2 = imagecolorallocate($NewImage,55,55,255);//line color 
$TextColor = imagecolorallocate($NewImage, 0, 0, 0);//text color-white

imageline($NewImage,0,30,rand(20,80),0,$LineColor);//create line 1 on image 
imageline($NewImage,rand(0,90),0,rand(10,60),rand(20,110),$LineColor);//create line 2 on image 
imageline($NewImage,rand(0,90),0,rand(10,60),rand(20,110),$LineColor2);//create line 2 on image 
imageline($NewImage,rand(0,90),0,rand(10,60),rand(20,110),$LineColor2);//create line 2 on image 

imagestring($NewImage, 26, 20, 5, $ResultStr, $TextColor);// Draw a random string horizontally 

$_SESSION['key'] = $ResultStr;// carry the data through session

header("Content-type: image/jpeg");// out out the image 

imagejpeg($NewImage);//Output image to browser 
imagedestroy($NewImage);

?>
